//
//  NetworkTools.swift
//  微博(swfit)
//
//  Created by YLW on 15/9/23.
//  Copyright © 2015年 YLW. All rights reserved.
//

import UIKit
import AFNetworking

enum requestMethod :String{
    case POST = "POST"
    case GET = "GET"
}

class NetworkTools: AFHTTPSessionManager {
    static  let sharedToos : NetworkTools = {
        let instance = NetworkTools(baseURL: nil)
        
        instance.responseSerializer.acceptableContentTypes?.insert("text/html")
        
        return instance
    }()
    
    
    
    func request(Method: requestMethod , urlStr : String , parameters :[String : AnyObject]? , finished : (result : AnyObject? , error : NSError?) -> ())
    {
        
        let success = { (task : NSURLSessionDataTask, response : AnyObject) -> Void in
            finished(result: response, error: nil)
            }
        
        let failure = {(task : NSURLSessionDataTask, error : NSError) -> () in
            finished(result: nil, error: error)
        }
        
        if Method == requestMethod.GET
        {
            GET(urlStr, parameters: parameters, success: success, failure: failure)
        }
        else if Method == requestMethod.POST
        {
            POST(urlStr, parameters: parameters, success: success, failure: failure)
        }
    }
}
